<template>
  <div class="tar-bar-item" @click="itemClick()">
    <div v-if="!isActive">
      <slot name="item-icon"></slot>
    </div>
    <div v-else>
      <slot name="item-icon-active"></slot>
    </div>
    <div :class="{active: isActive}">
      <slot  name="item-text"></slot>
    </div>
  </div>
</template>

<script>
  export default {
    name: 'TarBarItem',
    props: {
      path: String,
    },
    data() {
      return {
        name: String
      }
    },
    computed: {
      isActive(){
        // 若当前路由 是giant组件路径，则变成活跃
        console.log(this.$route.path.indexOf(this.path))
        return this.$route.path.indexOf(this.path) != -1
      }
    },
    methods: {
      itemClick () {
        console.log(this.path)
        this.isActive =true;
        this.$router.replace(this.path)
      }
    }
  }
</script>

<style scoped>
  .tar-bar-item {
    flex: 1;
    text-align: center;
    height: 49px;
    font-size: 14px;
  }
  .tar-bar-item img {
    width: 24px;
    height: 24px;
  }
  .active {
    color: blue;
  }
</style>
